Hello, |
Re: choice DBE Callback setDefault (dbe) Set that to some other button DBE.
|
Re: choice DBE Callback llandale - Mon Oct 03 19:45:39 EDT 2011
I'll just add, for future reference, that setDefault(DBE) must be called after the realize(DB). That solves half the problem. Would still be nice to have a Callback so I can use two editable choice DBEs on one DB. Oh well... |
Re: choice DBE Callback SystemAdmin - Tue Oct 04 04:53:21 EDT 2011 First I thought that simply defining a callBack routine for the choices using void set(DBE element, void callBack(DBE)) worked for me. It does when you type a new value and press enter. But unfortunately, when you select a value using the dropwdown list, then string s = get(DBE element) returns not the newly selected value, but the old value. But luckily, int i = get(DBE element) returns the correct value, and it even returns -1 when you have typed in a new value, hence we can differentiate all cases in the callBack:
DB mainDB
DBE ch1DBE, ch2DBE
string ch1[] = {"red", "green", "blue"}
string ch2[] = {"foo", "bar"}
void choiceCallBack(DBE dbe)
{ // General callBack routine for the choice DBE
int i = get dbe
string s = get dbe
string currVal = ""
if (i == -1){currVal = s}
else
{ // User selected a value from the dropdown list
// Unfortunately, 's' now has the wrong value,
// so we have to get the correct value using the
// returned integer and the original list of choices
if (dbe == ch1DBE){currVal = ch1[i]}
else if (dbe == ch2DBE){currVal = ch2[i]}
} // User selected a value from the dropdown list
infoBox currVal
} // General callBack routine for the choice DBE
mainDB = create "test"
ch1DBE = choice(mainDB, "", ch1, 0, 10, true)
ch2DBE = choice(mainDB, "", ch2, 0, 10, true)
set(ch1DBE, choiceCallBack)
set(ch2DBE, choiceCallBack)
show mainDB
|
Re: choice DBE Callback Peter_Albert - Tue Oct 04 05:24:15 EDT 2011 First I thought that simply defining a callBack routine for the choices using void set(DBE element, void callBack(DBE)) worked for me. It does when you type a new value and press enter. But unfortunately, when you select a value using the dropwdown list, then string s = get(DBE element) returns not the newly selected value, but the old value. But luckily, int i = get(DBE element) returns the correct value, and it even returns -1 when you have typed in a new value, hence we can differentiate all cases in the callBack:
DB mainDB
DBE ch1DBE, ch2DBE
string ch1[] = {"red", "green", "blue"}
string ch2[] = {"foo", "bar"}
void choiceCallBack(DBE dbe)
{ // General callBack routine for the choice DBE
int i = get dbe
string s = get dbe
string currVal = ""
if (i == -1){currVal = s}
else
{ // User selected a value from the dropdown list
// Unfortunately, 's' now has the wrong value,
// so we have to get the correct value using the
// returned integer and the original list of choices
if (dbe == ch1DBE){currVal = ch1[i]}
else if (dbe == ch2DBE){currVal = ch2[i]}
} // User selected a value from the dropdown list
infoBox currVal
} // General callBack routine for the choice DBE
mainDB = create "test"
ch1DBE = choice(mainDB, "", ch1, 0, 10, true)
ch2DBE = choice(mainDB, "", ch2, 0, 10, true)
set(ch1DBE, choiceCallBack)
set(ch2DBE, choiceCallBack)
show mainDB
For me, your code closes the DB when pressing enter - without fireing the callback. |
Re: choice DBE Callback SystemAdmin - Tue Oct 04 05:51:59 EDT 2011 Regards, Peter |
Re: choice DBE Callback Peter_Albert - Tue Oct 04 07:32:41 EDT 2011 |